﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class Province
    {
        private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public Province()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }

        public int Id { get; set; }
        public string ProvinceDisplay { get; set; }
        public string ProvinceName { get; set; }

        public int Insert(Province obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO Province(ProvinceDisplay,ProvinceName) values( N'{0}', N'{1}')"
                                       , obj.ProvinceDisplay, obj.ProvinceName);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(Province obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE Province SET ProvinceDisplay= '{0}', ProvinceName= N'{1}' Where Id= N'{2}'"
                                       , obj.ProvinceDisplay, obj.ProvinceName, obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Delete(Province obj)
        {
            int result = 0;
            string sql = string.Format("DELETE Province  Where id= N'{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}